import { userStore } from "@/store/user";

export const baseUrl = 'http://192.168.0.105:3000/';
export interface AxiosResponse<T = any> {
    code: number
    message: string
    data: T
  }

export const request = <T = any>(url: string, method: UniNamespace.RequestOptions['method']='GET', data: any = {}): Promise<AxiosResponse<T>> => {
    const uStore = userStore();
    return new Promise ((resolve, reject) => {
        uni.request({
            url: baseUrl + url, //仅为示例，并非真实接口地址。
            data,
            method,
            header: {
              token: uStore.token
            },
            success: (res: any) => {
                console.log(res.data);
                resolve(res.data);
          },
          complete: (res) => {
              console.log(baseUrl + url,res);
              
            }
        });
    }) 
} 